/// @tags: SegmentTree TD
#include <algorithm>
#include <cctype>
#include <cstdio>
using std::max;

namespace BlueQuantum {

int const N = 2500;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

int n, m, k;

struct ColSegTree {
  int mx[N], tag[N];

  void modify(int L, int R, int val, int x = 1, int l = 1, int r = m) {
    mx[x] = max(mx[x], val);
    if (L <= l && r <= R) return tag[x] = max(tag[x], val), void();
    int mid = (l + r) >> 1;
    if (L <= mid) modify(L, R, val, x << 1, l, mid);
    if (mid < R) modify(L, R, val, x << 1 | 1, mid + 1, r);
  }

  int query(int L, int R, int x = 1, int l = 1, int r = m) {
    if (L <= l && r <= R) return mx[x];
    int mid = (l + r) >> 1, ans = tag[x];
    if (L <= mid) ans = max(ans, query(L, R, x << 1, l, mid));
    if (mid < R) ans = max(ans, query(L, R, x << 1 | 1, mid + 1, r));
    return ans;
  }
};

struct RowSegTree {
  ColSegTree mx[N], tag[N];

  void modify(int L, int R, int colL, int colR, int val, int x = 1, int l = 1, int r = n) {
    mx[x].modify(colL, colR, val);
    if (L <= l && r <= R) return tag[x].modify(colL, colR, val);
    int mid = (l + r) >> 1;
    if (L <= mid) modify(L, R, colL, colR, val, x << 1, l, mid);
    if (mid < R) modify(L, R, colL, colR, val, x << 1 | 1, mid + 1, r);
  }

  int query(int L, int R, int colL, int colR, int x = 1, int l = 1, int r = n) {
    if (L <= l && r <= R) return mx[x].query(colL, colR);
    int mid = (l + r) >> 1, ans = tag[x].query(colL, colR);
    if (L <= mid) ans = max(ans, query(L, R, colL, colR, x << 1, l, mid));
    if (mid < R) ans = max(ans, query(L, R, colL, colR, x << 1 | 1, mid + 1, r));
    return ans;
  }
} seg;

inline int main() {
  read(n), read(m), read(k);
  for (int d, s, w, x, y; k; --k) {
    read(d), read(s), read(w), ++read(x), ++read(y);
    seg.modify(x, x + d - 1, y, y + s - 1, seg.query(x, x + d - 1, y, y + s - 1) + w);
  }
  printf("%d", seg.query(1, n, 1, m));
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P3437 [POI2006]TET-Tetris 3D.in", "r", stdin);
  freopen("P3437 [POI2006]TET-Tetris 3D.out", "w", stdout);
#endif
#endif

  return BlueQuantum::main();
}